package com.example.goods_manage.controller;

import com.example.goods_manage.dto.Goods;
import com.example.goods_manage.dto.request.GoodsRequest;
import com.example.goods_manage.service.GoodsService;
import com.example.goods_manage.utils.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <P> @Author: SongKeCheng
 * <P> Type: Class
 * <P> Description:
 * <P> Date: 2024/7/18:15:15
 */

@SuppressWarnings({"unchecked", ""})
@RestController
@RequestMapping("/goods")
public class GoodsController {
    private static final Logger log = LoggerFactory.getLogger(GoodsController.class);

    @Autowired
    private GoodsService goodsService;

    //findGoods
    @GetMapping("/findGoods")
    public AjaxResult findGoods(GoodsRequest goodsRequest){
        return goodsService.findGoods(goodsRequest);
    }

    /**
     * /goods/addGoods 新增商品信息
    */

    @PostMapping("/addGoods")
    public AjaxResult addGoods(@RequestBody GoodsRequest goodsRequest){
        return goodsService.addGoods(goodsRequest);
    }

    /**
     * /goods/updateGoods 更新商品信息
     */
    @PostMapping("/updateGoods")
    public AjaxResult updateGoods(@RequestBody GoodsRequest goodsRequest){
        return goodsService.updateGoods(goodsRequest);
    }

    /**
     * /goods/updateGoods 根据id 删除商品信息
     */
    @DeleteMapping("/deleteGoods")
    public AjaxResult deleteGoods(GoodsRequest goodsRequest){
        return goodsService.deleteGoods(goodsRequest);
    }


    //retrievalGoodsName

    /**
     * /goods/retrievalGoodsName 根据输入的名称 检索返回商品名称
     */
    @GetMapping("/retrievalGoodsName")
    public AjaxResult retrievalGoodsName(String goodsName){
        return AjaxResult.success(goodsService.retrievalGoodsName(goodsName));
    }
}
